import globals from "globals";
import js from "@eslint/js";
import tseslint from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import prettier from "eslint-plugin-prettier";
import importPlugin from "eslint-plugin-import";
import unusedImports from "eslint-plugin-unused-imports";

export default [
	js.configs.recommended, // JS 基础规则
	{
		files: ["**/*.ts", "**/*.tsx", "**/*.jsx", "**/*.js", "**/*.html", "**/*.vue"],
		languageOptions: {
			parser: tsParser,
			parserOptions: {
				ecmaVersion: "latest",
				sourceType: "module",
			},
			globals: {
				...globals.browser,
				...globals.node,
			},
		},
		plugins: {
			"@typescript-eslint": tseslint,
			prettier,
			import: importPlugin,
			"unused-imports": unusedImports,
		},
		rules: {
			// TypeScript 推荐规则
			...tseslint.configs.recommended.rules,

			// 删除未使用的 import
			"unused-imports/no-unused-imports": "error",

			// import 排序检查
			"import/order": [
				"warn",
				{
					groups: [["builtin", "external", "internal"]],
					"newlines-between": "always",
				},
			],

			// Prettier 格式校验
			"prettier/prettier": "warn",

			// 其他通用规则
			complexity: ["error", { max: 20 }],
			"prefer-const": "warn",
			"no-unused-vars": "warn",
			"@typescript-eslint/no-unused-vars": "warn",
		},
	},
];
